//
//  GuidViewController.m
//  App
//
//  Created by gome on 2018/11/27.
//  Copyright © 2018 gome. All rights reserved.
//

#import "GuidViewController.h"
#import "AppManager.h"
NSString *keys = @"ABCDEFGHIJKLMNOPQRSTUVWXYZ012345";

#import "BaseEncode.h"

#import "GCDTimer.h"

@interface GuidViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *backImage;
@property (nonatomic, strong) GCDTimer *timer;
@end

@implementation GuidViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    NSString *imageFile = [NSString stringWithFormat:@"%@/%@.jpeg", [[NSBundle mainBundle] resourcePath], @"autom"];
    UIImage* image = [UIImage imageWithContentsOfFile:imageFile];
    [_backImage setImage: image];
    
    
    self.timer = [[GCDTimer alloc] init];
    self.timer.timerInterval = 30;
    self.timer.precision = 1000;
    self.timer.isAscend = NO;
    self.timer.progressBlock = ^(GCDTime *progress) {
        dispatch_async(dispatch_get_main_queue(), ^{
            NSLog(@"%@\n", [NSString stringWithFormat:@"%@:%@:%@:%@", progress.hour, progress.minute, progress.second, progress.milliSecond]);
        });
    };
    self.timer.completion = ^{
        NSLog(@"complete done! ok 结束");
    };

    
    // Do any additional setup after loading the view from its nib.
}


/**
 登录按钮事件

 @param sender login button
 */
- (IBAction)clickLoginButton:(UIButton *)sender {
//    [[AppManager sharedInstance] showLoginPage];
    
//    [self.timer resume];
  
////数据格式化测试
//    NSArray *nameArray = @[@"里三低低里三低低低手", @"里三低低里三低低低", @"里三低低里三低低", @"里三低低里三低", @"里三低低里三", @"里三低低里", @"里三低低", @"里三低", @"里三", @"里"];
//
//    NSArray *mobileArray = @[@"18611111111", @"018600000001", @"018600000001",@"18611111111", @"018600000001", @"018600000001",@"18611111111", @"018600000001", @"018600000001", @"1233444"];
//
//    int i = 0;
//
//    while (i < 10) {
//
//        NSString *tempName = [self getName:nameArray[i] replaceString:@"*"];
//        NSString *tempMobile = [self getMobile:mobileArray[i] replaceString:@"****"];
//
//        NSLog(@"%@ %@", tempName, tempMobile);
//        i++;
//    }
    
 
//    base 测试
    NSString *hello= @"hi, this is my book! it's yours? en, her book is in backPackage!";

    NSString *list = @"ABCDEFGHI123JKLMNOPQRS456TUVWXYZ";

    NSString *base32String = [BaseEncode base32WithString:hello keys:list];

    NSLog(@"base32 string:%@", base32String);

    NSString *originString = [BaseEncode stringWithBase32:base32String keys:list];

    NSLog(@"%@", originString);
}


- (NSString *)getName:(NSString *)name replaceString:(NSString *)replaceString {
    
    if (!replaceString) {
        return name;
    }
    
    NSString *tempName = name.copy;
    long tempNameLength = 0;
    if (tempName) {
        tempNameLength = tempName.length;
        if (tempNameLength > 0) {
            NSRange range = NSMakeRange(1, 1);
            
            if (tempNameLength == 1) {
                return tempName;
            } else if (tempNameLength == 2) {
                range = NSMakeRange(1, 1);
            } else {
                range = NSMakeRange(1, tempNameLength - 2);
            }
            
            NSString *tempReplaceStrings = @"";
            long i = range.length;
            
            while (i > 0) {
                tempReplaceStrings = [tempReplaceStrings stringByAppendingString:@"*"];
                i--;
            }
            
            tempName = [tempName stringByReplacingCharactersInRange:range withString:tempReplaceStrings];
            
            return tempName;
        } else {
            return tempName;
        }
    }
    
    return nil;
}

- (NSString *)getMobile:(NSString *)mobile replaceString:(NSString *)replaceString {
    
    if (!replaceString) {
        return mobile;
    }
    
    NSString *tempMobile = mobile.copy;
    long tempMobileLength = 0;
    tempMobileLength = tempMobile.length;
    if (tempMobileLength == 11) {
        NSRange range = NSMakeRange(3, 4);
        
        tempMobile = [tempMobile stringByReplacingCharactersInRange:range withString:replaceString];
        
        return tempMobile;
        
    } else {
        return tempMobile;
    }
    
    return nil;
}


- (void)dealloc {
    NSLog(@"销毁对象 %@", [[self class] description]);
}





/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
